#!/usr/bin/python3

import requests
import sys
from lxml import etree

f = open(r'ck.txt', 'r')
cookies={}

for line in f.read().split(';'):
    name,value = line.strip().split('=', 1)
    cookies[name] = value
    #print(f'{name} = {value}')

f.close()

url = 'https://totheglory.im/takelogin.php'

headers = {
        'Referer': 'https://totheglory.im/login.php?returnto=',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36'
}


data = {
 "username": "xxx",
 "password": "xxx"
}

res = requests.post(url, cookies=cookies, headers=headers, data=data)

if res.status_code != 200:
    print("login error, exit")
    sys.exit(1)

print("login success")

url = "https://totheglory.im/userdetails.php?id=152195"
res = requests.get(url, cookies=cookies, headers=headers)

if res.status_code != 200:
    print("get userinfo failed")
    sys.exit(1)

#print(res.text)
html = etree.HTML(res.content)

lines = html.xpath('//span[@class="ipstate"]')
for l in lines:
    if ':' in l.text:
        continue
    print(l.text)

